<?php
namespace common\models;

use Yii;
use yii\base\NotSupportedException;
use yii\behaviors\TimestampBehavior;
use yii\db\ActiveRecord;

class Employees extends ActiveRecord
{
    const ACTIVE_STATUS = 1;
    const DISABLE_STATUS = 0;

    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return '{{%employees}}';
    }

    /**
     * @inheritdoc
     */
    public function behaviors()
    {
        return [
            'timestamp' => [
                'class' => 'yii\behaviors\TimestampBehavior',
                'attributes' => [
                    ActiveRecord::EVENT_BEFORE_INSERT => ['created_at', 'updated_at'],
                    ActiveRecord::EVENT_BEFORE_UPDATE => ['updated_at'],
                ],
            ],
        ];
    }

    public function getDepartments()
    {
        return $this->hasMany(Department::className(), ['id' => 'did'])->viaTable('emp_depart', ['eid' => 'id']);
    }

    public function getEmpdepart()
    {
        return $this->hasMany(EmpDepart::className(), ['eid' => 'id']);
    }

    public function getUser()
    {
        return $this->hasOne(User::className(), ['eid' => 'id']);
    }

}    